//
//  ListonListViewController.m
//  CwinCar
//
//  Created by dlios on 15/10/21.
//  Copyright © 2015年 dlios. All rights reserved.
//

#import "ListonListViewController.h"

@interface ListonListViewController ()

@end

@implementation ListonListViewController

-(void)viewWillAppear:(BOOL)animated
{
    _isPlaying = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    _stkPlay = [[STKAudioPlayer alloc]init];
    [self creatView];
    
}

-(void)creatView
{
    self.imageView = [[UIImageView alloc]init];
    self.imageView.frame = CGRectMake(mainScreen_Width/6., mainScreen_Width/6., mainScreen_Width*2/3., mainScreen_Width*2/3.);
    self.imageView.layer.masksToBounds = YES;
    self.imageView.layer.cornerRadius = mainScreen_Width/3.;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl]placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    [self.view addSubview:self.imageView];
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];
    
    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(mainScreen_Width/6., mainScreen_Width*5/6.+20, mainScreen_Width*2/3., 15)];
    timeLabel.text = self.time;
    timeLabel.textAlignment = NSTextAlignmentCenter;
    timeLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:timeLabel];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(mainScreen_Width/6., mainScreen_Width*5/6.+50, mainScreen_Width*2/3., 15)];
    titleLabel.text = self.titlee;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:titleLabel];
    
    //播放按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(mainScreen_Width/2.-25, mainScree_Height*3/4., 50, 50);
    [button setImage:[UIImage imageNamed:[NSString stringWithFormat: @"icon_video_play@2x"]] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"icon_video_stop@2x"] forState:UIControlStateSelected];
    button.backgroundColor = [UIColor clearColor];
    
    [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    
    
    //返回按钮
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed: @"iconfont-dismiss.png"] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(20, 20, 30, 30);
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
    
    
}
- (void)timeAction
{
    if (
        self.isPlaying)
    {   //设置旋转度
        self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, 0.01);
    }else
    {
        self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, 0);
    }
}

//返回按钮点击方法
-(void)back
{
    [_stkPlay stop];
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}
//播放按钮点击方法
-(void)button:(UIButton *)sender
{
    if (_isPlaying == NO) {
        
        [_stkPlay play:self.fileUrl];
        sender.selected = YES;
        _isPlaying = YES;
    }
    else
    {
        if (sender.selected == YES) {
            
            [_stkPlay pause];
            sender.selected = NO;
        }
        else
        {
            [_stkPlay resume];
            sender.selected = YES;
        }
        _isPlaying = NO;
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
